<?php
namespace Admin\Controller;

class DrinkController extends CommonController{
    
    public function chart(){
        $list = array();$listx = array();$listy = array();
        $firstDate = date('Y-m-d',strtotime("-".(date('j')-1)." day"));//本月1号日期
        $start_date = I('get.start_date') ? I('get.start_date') : $firstDate;
        $end_date = I('get.end_date') ? I('get.end_date') : date('Y-m-d');
        
        $list = D($this->controller)->field("*,sum(vol) as sum_vol")
                                    ->where(array('uid'=>I('get.uid'),'create_date'=>array('BETWEEN',array($start_date,$end_date))))
                                    ->group('create_date')->order('id asc')->select();
        //生成图表纵横轴数据
        foreach($list as $v){
            if($v['create_date'] && $v['sum_vol']){
                $listx[] = substr($v['create_date'],8,2);
                $listy[] = $v['sum_vol'];
            }
        }
        
        $this->assign('xStr',"'".implode("','",$listx)."'");
        $this->assign('yStr',implode(",",$listy));
        $this->assign('start_date',$start_date);
        $this->assign('end_date',$end_date);
        $this->display();
    }
    
}